<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Supplier extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('supplier', ['engine' => 'InnoDB', 'comment' => '供应商表', 'signed' => false]);
        $table->addColumn('dealer_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '经销商', 'after' => 'id'])
              ->addColumn('company_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '公司ID', 'after' => 'dealer_id'])
              ->addColumn('no', 'string', ['limit' => 100, 'default' => '', 'comment' => '供应商编号', 'after' => 'company_id'])
              ->addColumn('license_no', 'string', ['limit' => 100, 'default' => '', 'comment' => '营业执照编号', 'after' => 'no'])
              ->addColumn('tax_no', 'string', ['limit' => 100, 'default' => '', 'comment' => '税号', 'after' => 'license_no'])
              ->addColumn('name', 'string', ['limit' => 100, 'default' => '', 'comment' => '供应商名称', 'after' => 'license_no'])
              ->addColumn('short_name', 'string', ['limit' => 100, 'default' => '', 'comment' => '供应商简称', 'after' => 'name'])
              ->addColumn('contact', 'string', ['limit' => 100, 'default' => '', 'comment' => '联系人', 'after' => 'name'])
              ->addColumn('phone', 'string', ['limit' => 100, 'default' => '', 'comment' => '联系电话', 'after' => 'contact'])
              ->addColumn('province_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '省份ID', 'after' => 'short_name'])
              ->addColumn('city_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '城市ID', 'after' => 'province_id'])
              ->addColumn('area_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '区域ID', 'after' => 'city_id'])
              ->addColumn('address', 'string', ['limit' => 100, 'default' => '', 'comment' => '地址', 'after' => 'area_id'])
              ->addColumn('status', 'integer', ['default' => 1, 'limit' => 11, 'comment' => '状态：1启用 2禁用', 'after' => 'address'])
              ->addColumn('tax_rate', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, 'comment' => '税率', 'after' => 'status'])
              ->addColumn('type', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '结算方式:0现金,1微信、2支付宝、银行卡', 'after' => 'tax_rate'])
              ->addColumn('settlement_cycle', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '结算周期:0日结,1周结,2月结,3季结,4半年结,5年结', 'after' => 'type'])
              ->addColumn('settlement_day', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '结算日', 'after' => 'settlement_cycle'])
              ->addColumn('sort', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '排序', 'after' => 'status'])
              ->addColumn('logo', 'string', ['limit' => 255, 'default' => '', 'comment' => '公司logo', 'after' => 'sort'])
              ->addColumn('remark','string',['limit' => 255, 'default' => '', 'comment' => '备注', 'after' => 'type'])
              ->addColumn('create_time', 'integer', ['limit' => 11, 'default' => null, 'comment' => '创建时间', 'after' => 'remark'])
              ->addColumn('update_time', 'integer', ['limit' => 11, 'default' => null, 'comment' => '更新时间', 'after' => 'create_time'])
              ->addColumn('delete_time', 'integer', ['limit' => 11, 'default' => null, 'comment' => '删除时间', 'after' => 'update_time'])
              ->addIndex(['name','phone'], ['unique' => true, 'name' => 'idx_name_phone'])
              ->addIndex(['dealer_id'], ['name' => 'idx_dealer_id'])
              ->addIndex(['company_id'], ['name' => 'idx_company_id'])
              ->create();
    }
}
